﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;

/// <summary>
///cbsj_2 的摘要说明
/// </summary>
public partial class CBSJ
{
  public static DataSet Get_V_CBSJ(string sID)
  {
    string sSql = "select *,convert(varchar,cbsj,23) rq from v_SJLR_CBSJ where cbsjid=@0";
    SqlParameter[] cmdParams = { new SqlParameter("@0", SqlDbType.VarChar, 20) };
    cmdParams[0].Value = sID;
    DataSet ds = DbHelperSQL.Query(sSql, cmdParams);
    return ds;
  }
  public static DataSet Get_CBSJ(string sID)
  {
    string sSql = "select *,convert(varchar,cbsj,23) rq from SJLR_CBSJ where cbsjid=@0";
    SqlParameter[] cmdParams = { new SqlParameter("@0", SqlDbType.VarChar, 20) };
    cmdParams[0].Value = sID;
    DataSet ds = DbHelperSQL.Query(sSql, cmdParams);
    return ds;
  }
  public static CommandInfo Insert(CBSJ_Model model)
  {
    CommandInfo ci = new CommandInfo();
    string sql = @"insert into sjlr_cbsj values(@CBSJID,@DLM,@CBRID,@KHID,@CBSJ,@BYBS,@SJYQL,@CBBZ,
    @CBSJ_SFSB,@BQSJ,@SFSJ,@SFY,@YSQL,@YQXZ_BQQL,@LJYSQL,@SCBS,@SCCBSJ)";
    SqlParameter[] cmdParams = new SqlParameter[] { new SqlParameter("@CBSJID", SqlDbType.Int,4),
					new SqlParameter("@DLM", SqlDbType.VarChar,10),
					new SqlParameter("@CBRID", SqlDbType.Int,4),
					new SqlParameter("@KHID", SqlDbType.Int,4),
					new SqlParameter("@CBSJ", SqlDbType.DateTime),
					new SqlParameter("@BYBS", SqlDbType.BigInt,8),
					new SqlParameter("@SJYQL", SqlDbType.BigInt,8),
					new SqlParameter("@CBBZ", SqlDbType.VarChar,500),
					new SqlParameter("@CBSJ_SFSB", SqlDbType.Char,1),
					new SqlParameter("@BQSJ", SqlDbType.Int,4),
					new SqlParameter("@SFSJ", SqlDbType.DateTime),
					new SqlParameter("@SFY", SqlDbType.VarChar,10),
					new SqlParameter("@YSQL", SqlDbType.BigInt,8),
					new SqlParameter("@YQXZ_BQQL", SqlDbType.VarChar,200),
					new SqlParameter("@LJYSQL", SqlDbType.BigInt,8),
					new SqlParameter("@SCBS", SqlDbType.Int,4),
					new SqlParameter("@SCCBSJ", SqlDbType.DateTime)};
    cmdParams[0].Value = model.CBSJID;
    cmdParams[1].Value = model.DLM;
    cmdParams[2].Value = model.CBRID;
    cmdParams[3].Value = model.KHID;
    cmdParams[4].Value = model.CBSJ;
    cmdParams[5].Value = model.BYBS;
    cmdParams[6].Value = model.SJYQL;
    cmdParams[7].Value = model.CBBZ;
    cmdParams[8].Value = model.CBSJ_SFSB;
    cmdParams[9].Value = model.BQSJ;
    cmdParams[10].Value = model.SFSJ;
    cmdParams[11].Value = model.SFY;
    cmdParams[12].Value = model.YSQL;
    cmdParams[13].Value = model.YQXZ_BQQL;
    cmdParams[14].Value = model.LJYSQL;
    cmdParams[15].Value = model.SCBS;
    cmdParams[16].Value = model.SCCBSJ;
    ci.CommandText = sql;
    ci.Parameters = cmdParams;
    return ci;
  }
  public static CommandInfo Delete(string cbsjid)
  {
    string sql = "delete from sjlr_cbsj where cbsjid=@0";
    SqlParameter[] cmdParams = new SqlParameter[] { new SqlParameter("@0", SqlDbType.VarChar, 20) };
    cmdParams[0].Value = cbsjid;
    CommandInfo ci = new CommandInfo();
    ci.CommandText = sql;
    ci.Parameters = cmdParams;
    return ci;
  }
  /// <summary>
  /// 得到一个对象实体
  /// </summary>
  public static CBSJ_Model GetModel(int CBSJID)
  {
    StringBuilder strSql = new StringBuilder();
    strSql.Append("select  top 1 CBSJID,DLM,CBRID,KHID,CBSJ,BYBS,SJYQL,CBBZ,CBSJ_SFSB,BQSJ,SFSJ,SFY,YSQL,YQXZ_BQQL,LJYSQL,SCBS,SCCBSJ from SJLR_CBSJ ");
    strSql.Append(" where CBSJID=@CBSJID ");
    SqlParameter[] parameters = {
					new SqlParameter("@CBSJID", SqlDbType.Int,4)			};
    parameters[0].Value = CBSJID;

    CBSJ_Model model = new CBSJ_Model();
    DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
    if (ds.Tables[0].Rows.Count > 0)
    {
      return DataRowToModel(ds.Tables[0].Rows[0]);
    }
    else
    {
      return null;
    }
  }
  /// <summary>
  /// 得到一个对象实体
  /// </summary>
  public static CBSJ_Model DataRowToModel(DataRow row)
  {
    CBSJ_Model model = new CBSJ_Model();
    if (row != null)
    {
      if (row["CBSJID"] != null && row["CBSJID"].ToString() != "")
      {
        model.CBSJID = int.Parse(row["CBSJID"].ToString());
      }
      if (row["DLM"] != null)
      {
        model.DLM = row["DLM"].ToString();
      }
      if (row["CBRID"] != null && row["CBRID"].ToString() != "")
      {
        model.CBRID = int.Parse(row["CBRID"].ToString());
      }
      if (row["KHID"] != null && row["KHID"].ToString() != "")
      {
        model.KHID = int.Parse(row["KHID"].ToString());
      }
      if (row["CBSJ"] != null && row["CBSJ"].ToString() != "")
      {
        model.CBSJ = DateTime.Parse(row["CBSJ"].ToString());
      }
      if (row["BYBS"] != null && row["BYBS"].ToString() != "")
      {
        model.BYBS = long.Parse(row["BYBS"].ToString());
      }
      if (row["SJYQL"] != null && row["SJYQL"].ToString() != "")
      {
        model.SJYQL = long.Parse(row["SJYQL"].ToString());
      }
      if (row["CBBZ"] != null)
      {
        model.CBBZ = row["CBBZ"].ToString();
      }
      if (row["CBSJ_SFSB"] != null)
      {
        model.CBSJ_SFSB = row["CBSJ_SFSB"].ToString();
      }
      if (row["BQSJ"] != null && row["BQSJ"].ToString() != "")
      {
        model.BQSJ = int.Parse(row["BQSJ"].ToString());
      }
      if (row["SFSJ"] != null && row["SFSJ"].ToString() != "")
      {
        model.SFSJ = DateTime.Parse(row["SFSJ"].ToString());
      }
      if (row["SFY"] != null)
      {
        model.SFY = row["SFY"].ToString();
      }
      if (row["YSQL"] != null && row["YSQL"].ToString() != "")
      {
        model.YSQL = long.Parse(row["YSQL"].ToString());
      }
      if (row["YQXZ_BQQL"] != null)
      {
        model.YQXZ_BQQL = row["YQXZ_BQQL"].ToString();
      }
      if (row["LJYSQL"] != null && row["LJYSQL"].ToString() != "")
      {
        model.LJYSQL = long.Parse(row["LJYSQL"].ToString());
      }
      if (row["SCBS"] != null && row["SCBS"].ToString() != "")
      {
        model.SCBS = int.Parse(row["SCBS"].ToString());
      }
      if (row["SCCBSJ"] != null && row["SCCBSJ"].ToString() != "")
      {
        model.SCCBSJ = DateTime.Parse(row["SCCBSJ"].ToString());
      }
    }
    return model;
  }
  /// <summary>
  /// 更新一条数据
  /// </summary>
  public static CommandInfo Update(CBSJ_Model model)
  {
    StringBuilder strSql = new StringBuilder();
    strSql.Append("update SJLR_CBSJ set ");
    strSql.Append("DLM=@DLM,");
    strSql.Append("CBRID=@CBRID,");
    strSql.Append("KHID=@KHID,");
    strSql.Append("BYBS=@BYBS,");
    strSql.Append("SJYQL=@SJYQL,");
    strSql.Append("CBBZ=@CBBZ,");
    strSql.Append("CBSJ_SFSB=@CBSJ_SFSB,");
    strSql.Append("BQSJ=@BQSJ,");
    strSql.Append("SFSJ=@SFSJ,");
    strSql.Append("SFY=@SFY,");
    strSql.Append("YSQL=@YSQL,");
    strSql.Append("YQXZ_BQQL=@YQXZ_BQQL,");
    strSql.Append("LJYSQL=@LJYSQL,");
    strSql.Append("SCBS=@SCBS,");
    strSql.Append("SCCBSJ=@SCCBSJ");
    strSql.Append(" where CBSJID=@CBSJID ");
    SqlParameter[] parameters = {
					new SqlParameter("@DLM", SqlDbType.VarChar,10),
					new SqlParameter("@CBRID", SqlDbType.Int,4),
					new SqlParameter("@KHID", SqlDbType.Int,4),
					new SqlParameter("@BYBS", SqlDbType.BigInt,8),
					new SqlParameter("@SJYQL", SqlDbType.BigInt,8),
					new SqlParameter("@CBBZ", SqlDbType.VarChar,500),
					new SqlParameter("@CBSJ_SFSB", SqlDbType.Char,1),
					new SqlParameter("@BQSJ", SqlDbType.Int,4),
					new SqlParameter("@SFSJ", SqlDbType.DateTime),
					new SqlParameter("@SFY", SqlDbType.VarChar,10),
					new SqlParameter("@YSQL", SqlDbType.BigInt,8),
					new SqlParameter("@YQXZ_BQQL", SqlDbType.VarChar,200),
					new SqlParameter("@LJYSQL", SqlDbType.BigInt,8),
					new SqlParameter("@SCBS", SqlDbType.Int,4),
					new SqlParameter("@SCCBSJ", SqlDbType.DateTime),
					new SqlParameter("@CBSJID", SqlDbType.Int,4),
					new SqlParameter("@CBSJ", SqlDbType.DateTime)};
    parameters[0].Value = model.DLM;
    parameters[1].Value = model.CBRID;
    parameters[2].Value = model.KHID;
    parameters[3].Value = model.BYBS;
    parameters[4].Value = model.SJYQL;
    parameters[5].Value = model.CBBZ;
    parameters[6].Value = model.CBSJ_SFSB;
    parameters[7].Value = model.BQSJ;
    parameters[8].Value = model.SFSJ;
    parameters[9].Value = model.SFY;
    parameters[10].Value = model.YSQL;
    parameters[11].Value = model.YQXZ_BQQL;
    parameters[12].Value = model.LJYSQL;
    parameters[13].Value = model.SCBS;
    parameters[14].Value = model.SCCBSJ;
    parameters[15].Value = model.CBSJID;
    parameters[16].Value = model.CBSJ;
    CommandInfo ci = new CommandInfo();
    ci.CommandText = strSql.ToString();
    ci.Parameters = parameters;
    return ci;
  }
  public static string Get_TZSJ()
  {
    string sSql = "select * from s_tree";
    DataSet ds = DbHelperSQL.Query(sSql);
    return ds.Tables[0].Rows[0][0].ToString();
  }
}